<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="root"></div>
  <ul>
    <li><a href="#/a">/a</a></li>
    <li><a href="#/b">/b</a></li>
  </ul>
  <script>
    // hash 值发生变化触发 hashchange 事件
    window.addEventListener('hashchange', () => {
      const root = document.getElementById('root')
      console.log(window.location.href) // 获取当前hash值
      let pathname = window.location.hash.slice(1) // #/a -> /a
      root.innerHTML = pathname
    })
  </script>
</body>
</html>
